package co.edu.udistrital.analyzer.newversion;

import java.io.Reader;

import org.apache.lucene.analysis.ASCIIFoldingFilter;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.es.SpanishLightStemFilter;
import org.apache.lucene.analysis.snowball.SnowballFilter;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.Version;
import org.tartarus.snowball.ext.SpanishStemmer;

import com.edu.udistrital.util.Configuration;

public class AnalyzerLearningSpanish extends Analyzer {

	/**
	 * 
	 */
	public AnalyzerLearningSpanish(Version version) {
		super(version, Configuration.getInstance().getProperty(
				"stopWordsSpanish"));
	}

	@Override
	protected TokenStreamComponents createComponents(String arg0, Reader reader) {
		final Tokenizer source = new StandardTokenizer(MATCH_VERSION, reader);
		TokenStream result = new StandardFilter(MATCH_VERSION, source);
		result = new LowerCaseFilter(MATCH_VERSION, result);
		result = new ASCIIFoldingFilter(result);
		result = new StopFilter(MATCH_VERSION, result, STOPWORDS);

		if (MATCH_VERSION.compareTo(Version.LUCENE_36) >= 0) {
			result = new SpanishLightStemFilter(result);
		} else {
			result = new SnowballFilter(result, new SpanishStemmer());
		}
		return new TokenStreamComponents(source, result);
	}

}
